This article describes how the code view works in Rational Software Architect RealTime Edition (RSARTE).

 

The code view is a convenient view for editing code in the model. The code view is implemented as an Eclipse view and enables you to edit code directly in the model. When you click on model elements that have one or more code snippets, such as operations, transitions, or states (entry and exit actions), a code snippet for that element is shown in the code view and you can edit it directly.

When using the UML Development perspective, the code view appears by default in the lower right-hand corner, along with the other views such as Console, Problems, and Search. However, the code view can be closed at any time.  If you want to open the code view again, you can do so from Window - Show View - Code View.

You can also open the code view using the command "Show Code View", available in the context menu for all model elements that have at least one code snippet.

You can only have one code view open at a time. If you want to work with multiple code snippets and need more space for editing, use the code editor instead. Open the code editor by selecting "Show Source in Editor" from the context menu of model elements (refer to the previous image.) For transitions, operations, attributes, and parameters, you can also open a code editor by double-clicking on the element in the Project Explorer.

 

The code view pane is organized as shown in the following image:

Model element

The name and type of the currently selected model element for editing. The code language is also printed (C++ in the previous example). You can select and copy this text, but not edit it.

Mode

Indicates whether the code snippet displayed is from the model or from a generated file. If the code snippet is from a generated file, the "file" word is a hyperlink that you can click to look at the code snippet in the context of the generated file using the CDT editor.

Link to model element This hyperlink enables you to navigate to the model element currently selected for editing. The navigation selects the element in the Project Explorer and in diagrams. If the code view is not wide enough to show the entire label for the model element, it is truncated in the middle using an ellipsis (...).

Toolbar icons

Show Source in Editor: CTRL+SHIFT+F3

Opens the code snippet in a separate code editor. This is useful for comparing code, since you might have more than one code editor open at the same time for different model elements. The code editor usually gives you more space for editing than what the code view does.

 

Launch External Editor: SHIFT+F3

Launches an external text editor for editing the code, if the editor is defined in the code view preferences (right-click in the code view and select "Preferences").

 

Load Generated Source: CTRL+SHIFT+L

Loads the generated source code so that the code view can edit the generated version of the code snippet rather than the source version stored in the model. In this mode, the code view displays "Showing code from the file" in its header area; This is the recommended mode for editing a code snippet, since all advanced editing features that require a complete generated source code file (such as full content assist) are available.

Code area

The area where you can view and edit your code snippet.

Code snippet selector

This is either a drop down menu (as shown in the Code View example) or a set of tabs (the default). You can use the drop down menu or the tabs to select the code snippet of the selected model element to edit.

For example, for a transition, you have two code snippets to choose from:

The code snippets that are not empty are displayed in bold type in this drop down.

The following is how the code view looks when using tabs instead of a drop down menu as the code snippet selector:

You can see that the "Guard" code snippet is not empty, since its label is displayed in bold text in the tab. If you close a tab, you can reopen the tab by right-clicking the area next to the tabs. A context menu appears that lists all available code snippets not currently shown in a tab.

A preference controls whether to use a drop down menu or tabs as the code snippet selector: Select Code View - Code View Style

 

Now let's look at the different stages of code editing and answer questions such as:

  • When are the code changes made in the code view committed to the model?

  • When is the model saved?

  • When is code generated?

     

Model State

User Action

Result / Indication

The model is saved. Code has not yet been generated.

 

No dirty flags (*) on any editor or view tabs.

 

Clicks on an element in the Project Explorer, such as a transition.

Code is shown in the code view (assuming the code view is open). The mode is "Showing code from the model".









 

User starts making changes to the code in code view.

At this point, the code is not committed to the model so the model is not dirty. No dirty flags (*) on the open editors or Project Explorer view.

Pressing CTRL+Z (Undo) removes any new edits since the last save.

 

User clicks out of code view.

Code is now committed to the model, but the model is not saved, nor is the new code generated. Dirty flags (*) are visible on model editors and views (but not on the code view itself).

Model is modified ("dirty") but not saved. Code has not been generated.

 

Dirty flags (*) are visible on model editors and views (but not on the code view itself).









 

User presses CTRL+S (Save) or CTRL+SHIFT+S (Save All) from anywhere (including inside code view after making changes).

The model is saved. If the user presses CTRL+S or CTRL+SHIFT+S inside the code view, any newly made edits in the code view are first committed to the model, before the model is saved.

The model is saved. Code has not yet been generated.

 

The model is returned to the starting state (as in the first row of this table).



 

User builds a transformation configuration that involves generating code for the selected element.

A CDT target project gets generated, containing several generated C++ files.

 

User presses CTRL+SHIFT+L inside the code view.

Generated source code is loaded and the code view now shows the code snippet from the generated file instead. The mode is changed to "Showing code from the file".

 



Let's finish by answering some frequently asked questions about the code view:

When is the code committed to the model?

Code is committed to the model when the user does any of the following:

When is the model saved?

The model is saved when one of the following occurs:

When is code generated?

Code is generated when building or running a transformation configuration.

How can I undo any edits that I have made in the code view?

Pressing CTRL+Z (Undo) in the code view will undo any changes that have been made since the last time the code was committed to the model. When you have committed your changes to the model, you can also undo the entire commit operation, by selecting Undo in the Project Explorer or an editor.

How can I compare multiple code snippets from the same or different model elements?

You can only have one code view open at a time, but you can compare different code snippets by using the "Show Source in Editor" command (CTRL+SHIFT+F3). This transfers the code from the code view to a code editor. Select another model element and use the "Show Source in Editor" command again to transfer the code to a different code editor. Drag the code editors in Eclipse so that they are side by side for easier comparison of the code snippets.

How can I view a code snippet in the code view, if it is already shown in a code editor?

When you close the code editor, the code will be shown in the code view instead. However, if you have several code editors open, it can be difficult to know which one of them to close. Find the code editor by clicking on the hyperlink that is shown in the code view in this case: